module Interface.Base 
	(
		createWindow,
		createChild,
		
	) 
where

import System.IO
import Graphics.UI.Gtk
import Storage.Basic


---------------PURE--------------------

defaultWidth = 600
defaultHeight = 600
title = "hIDE"

---------------------------------------

createWindow child = do
	window <- windowNew
	set window [
		windowDefaultWidth := defaultWidth,
		windowDefaultHeight := defaultHeight,
		windowTitle := title,
		containerChild := child
		]
	onDestroy window mainQuit
	return window

---

-- codigo asqueroso para la creacion de la ventana

createChild  = do
	box <- vBoxNew False 0

	menuBar <- menuBarNew
	fileItem <- menuItemNewWithLabel "file"
	
	fileSubMenu <- menuNew
	saveItem <- menuItemNewWithLabel "save"
	loadItem <- menuItemNewWithLabel "load"
	exitItem <- menuItemNewWithLabel "exit"
	menuShellAppend fileSubMenu saveItem
	menuShellAppend fileSubMenu loadItem
	menuShellAppend fileSubMenu exitItem

	menuItemSetSubmenu fileItem fileSubMenu
	menuShellAppend menuBar fileItem


	boxPackStart box menuBar PackNatural 0

	hbox <- hBoxNew True 0
	containerSetBorderWidth hbox 5
	textView <- textViewNew
	containerAdd hbox textView

	containerAdd box hbox


	buffer <- textViewGetBuffer textView
	
	onSelect saveItem $ createSaveAction $ getText buffer

	return box



------ ACA TERMINA EL CODIGO ASQUEROSO

createSaveAction doc = do
	text <- doc
	save text
	return ()

getText buffer = do
	start <- textBufferGetStartIter buffer
	end <- textBufferGetEndIter buffer
	textBufferGetText buffer start end True


{--



createBox = do
	box <- hBoxNew True 0
	containerSetBorderWidth box 5
	createEntry >>= containerAdd box
	return box

createMainContainer = do
	box <- vBoxNew False 0
	menu <- createMenu
	boxPackStart box menu PackNatural 0
	createBox >>= containerAdd box
	return box

createEntry = do
	text <- textViewNew
	return text


createMenu = do
	menuBar <- menuBarNew
	fileItem <- createFileItem
	fileSubMenu <- createFileSubMenu
	menuItemSetSubmenu fileItem fileSubMenu
	menuShellAppend menuBar fileItem
	return menuBar

createFileItem = menuItemNewWithLabel "file"

createFileSubMenu = do
	menu <- menuNew
	saveItem <- menuItemNewWithLabel "save"
	loadItem <- menuItemNewWithLabel "load"
	exitItem <- menuItemNewWithLabel "exit"
	menuShellAppend menu saveItem
	menuShellAppend menu loadItem
	menuShellAppend menu exitItem
	return menu

--}

